// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: wsfuyibing <682805@qq.com>
// Date: 2024-11-12

package conf

const (
    DefaultFileLoggerName      = "2006-01-02.log"
    DefaultFileLoggerPath      = "./logs"
    DefaultFileLoggerSeparator = "2006-01"
)

// FileAdapterConfig
// 文本适配器, 日志写入到文件中.
//
//   - /var/logs/sketch/2024-01/2024-01-10.log
type FileAdapterConfig struct {
    // Sync
    // 是否同步, 在同步模式日志顺序写入文件, 但是影响业务执行速度. 默认为 false, 即
    // 异步写入.
    //
    // default: false
    Sync bool `yaml:"sync"`

    // Json
    // 是否输出JSON格式.
    //
    // default: false
    Json bool `yaml:"json"`

    // FileName
    // 文件名.
    //
    // default: 2024-01-10.log
    FileName string `yaml:"name"`

    // FilePath
    // 存储位置.
    //
    // default: ./logs
    FilePath string `yaml:"path"`

    // FileSeparator
    // 分隔模式.
    //
    // default: 2006-01 (按月分隔)
    FileSeparator string `yaml:"separator"`
}

// +---------------------------------------------------------------------------+
// | Access methods                                                            |
// +---------------------------------------------------------------------------+

func (o *FileAdapterConfig) init() {
    if o.FileName == "" {
        o.FileName = DefaultFileLoggerName
    }
    if o.FilePath == "" {
        o.FilePath = DefaultFileLoggerPath
    }
    if o.FileSeparator == "" {
        o.FileSeparator = DefaultFileLoggerSeparator
    }
}
